
$("#paramxmlfile").on("change", function(evt) {
    var paramFlieresString=$("#paramxmlfile").val();
    var str = paramFlieresString.split("\\");
    var paramFlieres = str[str.length-1];
    if(paramFlieres!=""){
        $('#paramfileShow_div').html(paramFlieres);
        $("#paramfileShow_div").show();

    }else{
        $('#paramfileShow_div').html('您还没有输入任何东西');
        $("#paramfileShow_div").show();
    }
    var algo={
        algorithInfo:1
    };
   getXmlInformation(evt);
});

function showDetail() {
    $.ajax({
        url:constUrl+"CompanyServlet",
        type:'post',
        data:{
            operateType:"showAll",
            onePageCount:"10",
            currentPage:"1"
        },
        dataType:'json',
        success: function(responseText) {
            var companyHtml ='';
            for(var i=0;i<responseText.datas.length;i++){
                companyHtml+='<option value="'+(responseText.datas[i].companyId)+'" >'+responseText.datas[i].companyName+'</option>'

            }
            $("#jsonInfo").attr("aString",companyHtml);
        },
        complete: function() {
        },
        error: function() {
        }
    });
        layer.ready(function() {
            //官网欢迎页
            layer.open({
                type: 2,
                skin: 'layui-layer-lan',
                title: '算法详情预览',
                fix: false,
                scrollbar: false,
                shadeClose: true,
                maxmin: true,
                area: ['1080px', '600px'],
                content:constUrl +'views/algorithm/xmlcheck.action'
            });
        });
}

function stringToxml(data) {
    var xmlobject;
    if (window.ActiveXObject) {
        xmlobject = new ActiveXObject("Microsoft.XMLDOM");
        xmlobject.async = "false";
        xmlobject.loadXML(data);
    }
    else {
        var parser = new DOMParser();
        xmlobject = parser.parseFromString(data, "text/xml");
    }
    return xmlobject
}
function getXmlInformation(evt) {
    var f = evt.target.files[0];
    var zipName = f.name.split(".")[0]
    console.log(zipName);
    JSZip.loadAsync(f)
        .then(function(zip) {
            zip.file(zipName+"/"+zipName+".xml").async("string").then(function (data_temp) {
                var xmlDom = stringToxml(data_temp);
                var algorithmInfo = new Object();
                algorithmInfo.name = xmlDom.getElementsByTagName("name")[0].textContent;
                console.log(algorithmInfo.name);
                algorithmInfo.algorithmType = xmlDom.getElementsByTagName("field")[0].textContent;
                algorithmInfo.algorithmFunction = xmlDom.getElementsByTagName("algorithmFunction")[0].textContent;
                algorithmInfo.version = xmlDom.getElementsByTagName("version")[0].textContent;
                algorithmInfo.companyName = xmlDom.getElementsByTagName("company")[0].textContent;
                algorithmInfo.introduction = xmlDom.getElementsByTagName("introduction")[0].textContent;
                algorithmInfo.platform = xmlDom.getElementsByTagName("platform")[0].textContent;
                algorithmInfo.postfix = xmlDom.getElementsByTagName("postfix")[0].textContent;
                algorithmInfo.isContainGpu = xmlDom.getElementsByTagName("gpu")[0].textContent;
                algorithmInfo.isUseMpi = xmlDom.getElementsByTagName("mpi")[0].textContent;
                if(xmlDom.getElementsByTagName("cpuNum").length>0){
                    algorithmInfo.cpuNum = xmlDom.getElementsByTagName("cpuNum")[0].textContent;
                }else{
                    algorithmInfo.cpuNum = 0;
                }
              //  algorithmInfo.isLeft = xmlDom.getElementsByTagName("isLeft")[0].textContent;
                algorithmInfo.isLeft = "false";

                var file = xmlDom.getElementsByTagName("file");
                var AlgorithmOutput = xmlDom.getElementsByTagName("AlgorithmOutput");
                var InputParam = xmlDom.getElementsByTagName("InputParam");
                var inputfiles = new Array();
                var AlgorithmOutputs = new Array();
                var AlgorithmParams = new Array();
                console.log(file.length);
                for(var i=0;i< file.length;i++){
                    if(file[i].getElementsByTagName("suffix").length>0){
                        inputfiles.push({
                            inputName:file[i].getElementsByTagName("fileParam")[0].textContent,
                            type:file[i].getElementsByTagName("fileType")[0].textContent,
                            inputIntroduction:file[i].getElementsByTagName("fileIntroduction")[0].textContent,
                            suffix:file[i].getElementsByTagName("suffix")[0].textContent
                        })
                    }else{
                        inputfiles.push({
                            inputName:file[i].getElementsByTagName("fileParam")[0].textContent,
                            type:file[i].getElementsByTagName("fileType")[0].textContent,
                            inputIntroduction:file[i].getElementsByTagName("fileIntroduction")[0].textContent,
                            suffix:""
                        })
                    }

                }
                algorithmInfo.inputCount =inputfiles;

                for(var i=0;i< AlgorithmOutput.length;i++){
                    if(AlgorithmOutput[i].getElementsByTagName("suffix").length>0){
                        AlgorithmOutputs.push({
                            outputName:AlgorithmOutput[i].getElementsByTagName("outputName")[0].textContent,
                            type:AlgorithmOutput[i].getElementsByTagName("outputType")[0].textContent,
                            outputIntroduction:AlgorithmOutput[i].getElementsByTagName("outputIntroduction")[0].textContent,
                            suffix:AlgorithmOutput[i].getElementsByTagName("suffix")[0].textContent
                        })
                    }else{
                        AlgorithmOutputs.push({
                            outputName:AlgorithmOutput[i].getElementsByTagName("outputName")[0].textContent,
                            type:AlgorithmOutput[i].getElementsByTagName("outputType")[0].textContent,
                            outputIntroduction:AlgorithmOutput[i].getElementsByTagName("outputIntroduction")[0].textContent,
                            suffix:""
                        })
                    }

                }
                algorithmInfo.outputCount = AlgorithmOutputs;

                for(var i=0;i< InputParam.length;i++){
                    AlgorithmParams.push({
                        paramSymbol:InputParam[i].getElementsByTagName("param")[0].textContent,
                        paramType:InputParam[i].getElementsByTagName("paramType")[0].textContent,
                        paramIntroduction:InputParam[i].getElementsByTagName("paramIntroduction")[0].textContent,
                        paramDefaultValue:InputParam[i].getElementsByTagName("value")[0].textContent
                    })
                }
                algorithmInfo.paramsCount = AlgorithmParams;
                var algorithmInfo_json = JSON.stringify(algorithmInfo);
                var jsonP_ = algorithmInfo_json;
                console.log(jsonP_);
                jsonP_ = eval("("+jsonP_+")");
                if(jsonP_==0){
                    layer.msg("请选择文件！");
                }else {
                    $("#jsonInfo").attr("aName", jsonP_.name);
                    $("#jsonInfo").attr("aversion", jsonP_.version);
                    $("#jsonInfo").attr("atype", jsonP_.algorithmType);
                    $("#jsonInfo").attr("afunction", jsonP_.algorithmFunction);
                    $("#jsonInfo").attr("acompanyName", jsonP_.companyName);
                    $("#jsonInfo").attr("aintroduction", jsonP_.introduction);
                    $("#jsonInfo").attr("apostfix", jsonP_.postfix);
                    $("#jsonInfo").attr("aplatform", jsonP_.platform);
                    $("#jsonInfo").attr("acontainGpu", jsonP_.isContainGpu);
                    $("#jsonInfo").attr("auseMpi", jsonP_.isUseMpi);
                    $("#jsonInfo").attr("acpuNum", jsonP_.cpuNum);
                    $("#jsonInfo").attr("aisLeft", jsonP_.isLeft);
                    $("#jsonInfo").attr("ainputCount", jsonP_.inputCount.length);
                    $("#jsonInfo").attr("aoutputCount", jsonP_.outputCount.length);
                    $("#jsonInfo").attr("aparamsCount", jsonP_.paramsCount.length);
                    for (var i = 0; i < jsonP_.inputCount.length; i++) {
                        $("#jsonInfo").attr("inputName" + i, jsonP_.inputCount[i].inputName);
                        $("#jsonInfo").attr("inputType" + i, jsonP_.inputCount[i].type);
                        $("#jsonInfo").attr("inputIntroduction" + i, jsonP_.inputCount[i].inputIntroduction);
                        $("#jsonInfo").attr("inputSuffix" + i, jsonP_.inputCount[i].suffix);
                    }
                    for (var i = 0; i < jsonP_.outputCount.length; i++) {
                        $("#jsonInfo").attr("outputName" + i, jsonP_.outputCount[i].outputName);
                        $("#jsonInfo").attr("outputType" + i, jsonP_.outputCount[i].type);
                        $("#jsonInfo").attr("outputIntroduction" + i, jsonP_.outputCount[i].outputIntroduction);
                        $("#jsonInfo").attr("outputSuffix" + i, jsonP_.outputCount[i].suffix);
                    }
                    for (var i = 0; i < jsonP_.paramsCount.length; i++) {
                        $("#jsonInfo").attr("paramSymbol" + i, jsonP_.paramsCount[i].paramSymbol);
                        $("#jsonInfo").attr("paramType" + i, jsonP_.paramsCount[i].paramType);
                        $("#jsonInfo").attr("paramIntroduction" + i, jsonP_.paramsCount[i].paramIntroduction);
                        $("#jsonInfo").attr("paramDefaultValue" + i, jsonP_.paramsCount[i].paramDefaultValue);

                    }
                }
            });
        });


}